package Annotation;

import Util.HibernateUtil;

import java.lang.annotation.*;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by studio on 2017/3/29.
 */

public class MyAnnotation {

    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    @Inherited
    @Documented
    public @interface Database{
        public String driver_class() default "com.mysql.jdbc.Driver";
        public String username();
        public String password();
        public String DBName();
        public String IP() default "localhost";
    }

    public static Map getDBInfo(Class<?> clazz){
        Map arr = new HashMap();
        Method[] methods = clazz.getMethods();

        for (Method method : methods){
            if(method.isAnnotationPresent(Database.class)){
                arr.put("driver_class",method.getAnnotation(Database.class).driver_class());
                arr.put("username",method.getAnnotation(Database.class).username());
                arr.put("password",method.getAnnotation(Database.class).password());
                arr.put("DBName",method.getAnnotation(Database.class).DBName());
                arr.put("IP",method.getAnnotation(Database.class).IP());
            }
        }

        return arr;
    }
}
